﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace DnPakExplorer.Controls {

	public partial class ImageBox : UserControl {

		[Category("Image")]
		public Image ImagePic { get; set; }

		[Category("Image")]
		public Rectangle SrcRect { get; set; }

		[Category("Image")]
		public bool SpriteDraw { get; set; }

		[Category("Image")]
		public Rectangle SpriteRect { get; set; }

		public ImageBox() {
			InitializeComponent();
			SetStyle(ControlStyles.AllPaintingInWmPaint
				|ControlStyles.OptimizedDoubleBuffer
				|ControlStyles.UserPaint
				|ControlStyles.ResizeRedraw, true);
		}

		private void ImageBox_Paint(object sender, PaintEventArgs e) {
			if (ImagePic != null) {
				if (SpriteDraw)
					Sprite.Draw(e.Graphics, ImagePic, ClientRectangle,
						new Rectangle(SrcRect.X+SpriteRect.X, SrcRect.Y+SpriteRect.Y, SpriteRect.Width, SpriteRect.Height), SrcRect);
				else
					e.Graphics.DrawImage(ImagePic, ClientRectangle, SrcRect, GraphicsUnit.Pixel);
			}
		}
	}
}
